<style>
    .xxpayPopupDiv .layui-form-label {
        width:120px !important;
        margin-left:1%;
    }
    .xxpayPopupDiv .layui-input-inline {
        width: 80% !important;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <div class="layui-tab-content">
                <form class="layui-form center">


                    <div class="layui-form-item">
                        <label class="layui-form-label">通道文件</label>
                        <div class="layui-input-inline">
                            <input type="text" readonly id="uploadJarInput" class="layui-input layui-input-inline" style="width: 300px!important;">
                            <button id="uploadJarBtn" type="button" class="layui-btn layui-btn-sm layui-btn-warm" style="margin-left: 10px;">
                                <i class="layui-icon">&#xe67c;</i>选择【 zip 】文件
                            </button>
                        </div>
                    </div>

                    <div style="color:red">
                        <p>提示：</p><br/>
                        <p>1. 请确保该文件为官方下载的文件，否则无法正常导入；</p><br/><br/>
                        <p>2. 如需获取接口文件请点击<a target="_blank" href="http://www.xxpay.vip/ifstore/list.html" class="layui-btn layui-btn-sm layui-btn-primary" style="margin-left: 10px;">
                            <i class="layui-icon">&#xe7ae;</i>获取文件
                        </a>;</p><br/><br/>
                        <p>3. 导入成功将覆盖现有的接口配置，可能导致现有配置失效，请确认配置参数后再导入；</p>
                    </div>

                    <button type="button" class="layui-hide xxpayYesBtn" lay-submit="" lay-filter="add">保存</button>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form','table','util','admin','upload'],function(){
        var form = layui.form
        , $ = layui.$
        , admin = layui.admin
        , layer = layui.layer 
        , element = layui.element
        ,upload = layui.upload
        , table = layui.table;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息

        form.render();

        //创建一个上传组件
        var uploadObj = upload.render({
            elem: '#uploadJarBtn'
            ,auto: false
            ,multiple: false
            ,accept: 'file'
            ,headers: {access_token: layui.data(layui.setter.tableName).access_token}
            ,acceptMime: "application/zip,application/x-zip,application/x-zip-compressed"
            ,choose: function(fileObj){ //上传后的回调

                //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                var files = fileObj.pushFile();
                fileObj.preview(function(index, chooseFile, result){  //异步处理

                    $("#uploadJarInput").val($("#uploadJarInput").parent().find('.layui-upload-file').val());
                });
            },done: function(res, index, upload){ //上传完成


                if(res.code == '0'){
                    layer.alert("导入成功", {title: '提示'},function(index){
                        layer.closeAll(); //关闭所有弹层
                        layui.table.reload('tableReload', {page: {curr: 1}}); //调用业务弹层外表格重新加载
                    });
                }else{

                    layer.alert(res.msg);
                }
            }
        });


        //
        form.on('submit(add)', function(data){

            if( !$("#uploadJarInput").val() ){
                return layer.msg('请选择您下载的接口【zip】文件！');
            }

            layer.confirm('确认导入接口文件？', function(index){

                uploadObj.config.url = layui.setter.baseUrl + '/ifstoreApp/install',
                uploadObj.config.data = {access_token: layui.data(layui.setter.tableName).access_token}; //必要参数
                uploadObj.upload();  //请求上传

            });
        });

    })
</script>